# -*- coding: utf-8 -*-
# @project: huawang-api20230914
# @file： yk_data.py
# @Time：2023/7/24 10:22
# @Author：lizhixiong
"""
为方便测试，编写一些构造测试数据的脚本
花王云客
"""
from po.public_methods import yk_ui_login_backstage, yk_ht_api_login
from po.yk.ht.ht_api import YkHtApi
import time, json

if __name__ == '__main__':
    test_flag = 2

    if test_flag == 1:
        drive = yk_ui_login_backstage()
        cooke = drive.get_cookies()[-1]['value']
         # 获取到的token需要替换掉"%20"为空
        token = cooke.replace('%20', ' ')
        """生产环境获取token"""
        res = YkHtApi()
        # print(res.add_product(token, mod=3, Pro=True))
        print(res.add_product(token, mod=2, Pro=True))
        # print(res.add_product(token, mod=1, Pro=True))

        # # time.sleep(5)
        # print(res.list_product(token,id=False))
        # deleteId=res.list_product(token,Did=True)
        # print(res.Delete_product(token, deleteId))

    elif test_flag == 2:
        """test环境获取token"""
        token = yk_ht_api_login()
        res = YkHtApi()
        # print(res.add_product(token, mod=3, Pro=False))
        print(res.add_product(token, mod=2, Pro=False))
        # print(res.add_product(token,mod=1, Pro=False))
        time.sleep(1)
        for one in json.loads(res.list_Unlisted_goods(token))['content']:
            # print(one['id'],one['storeName'])
            if "auto_test" in one['storeName']:
                res.up_goods(token,one['id'])
                # res.Delete_product(token,one['id'],Pro_url=False)
